class Solution {
public:
    bool isAnagram(string s, string t) {
        int hash1[26] = { 0 };
        int hash2[26] = { 0 };
        for (auto& ch : s) hash1[ch - 'a']++;
        for (auto& ch : t) hash2[ch - 'a']++;
        for (int i = 0; i < 26; i++)
            if (hash1[i] != hash2[i])
                return false;
        return true;
    }
};

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        vector<vector<string>> ret;
        unordered_map<string, vector<string>> hash;
        for (auto str : strs)
        {
            string s = str;
            sort(s.begin(), s.end());
            hash[s].emplace_back(str);
        }
        for (auto& v : hash)
        {
            ret.emplace_back(v.second);
        }
        return ret;
    }
};